//
//  ThirdViewController.m
//  Objective-cDemo
//
//  Created by ShareAnimation on 2019/8/30.
//  Copyright © 2019 爱丽丝的梦境. All rights reserved.
//

#import "ThirdViewController.h"
#import <QuickLook/QuickLook.h>
@interface ThirdViewController ()<QLPreviewControllerDelegate,QLPreviewControllerDataSource>
@property (strong, nonatomic) NSArray *items;
@end

@implementation ThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"点击" style:UIBarButtonItemStyleDone target:self action:@selector(doRightAction)];
    
    self.items = @[@"WechatIMG197.jpeg"];
}

- (void)doRightAction {
    QLPreviewController *vc = [QLPreviewController new];
    vc.delegate = self;
    vc.dataSource = self;
    [vc setCurrentPreviewItemIndex:0];
    [self presentViewController:vc animated:true completion:nil];
}


- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
    return self.items.count;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    NSString* path = [[NSBundle mainBundle] pathForResource:self.items[index] ofType:nil];
    
    return [NSURL fileURLWithPath:path];
}
- (void)previewControllerDidDismiss:(QLPreviewController *)controller
{
    NSLog(@"预览界面已经消失");
}

@end
